import { defHttp } from '/@/utils/http/axios';
import { LoginParams, LoginResultModel, GetUserInfoModel } from './model/userModel';
import { ContentTypeEnum } from '/@/enums/httpEnum';

import { ErrorMessageMode } from '/#/axios';

enum Api {
  Login = '/admin-api/system/auth/login',
  Logout = '/admin-api/system/auth/logout',
  GetUserInfo = '/admin-api/system/auth/get-permission-info',
  GetPermCode = '/getPermCode',
  GetCaptcha = '/admin-api/system/captcha/get',
  GetProfile = '/admin-api/system/user/profile/get',
  UpdateProfile = '/admin-api/system/user/profile/update',
  uploadAvatarApi = '/admin-api/system/user/profile/update-avatar',
  UploadPwdApi = '/admin-api/system/user/profile/update-password',
  refreshToken = '/admin-api/system/auth/',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'none') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}
export function reToken(params) {
  return defHttp.post<string[]>({ url: Api.refreshToken, params });
}
export function getProfile() {
  return defHttp.get<string[]>({ url: Api.GetProfile });
}
export function uploadPwdApi(params) {
  return defHttp.put<any[]>({ url: Api.UploadPwdApi, params });
}
// 用户头像上传
export function uploadAvatarApi(data) {
  return defHttp.put({
    url: Api.uploadAvatarApi,
    headers: {
      'Content-type': ContentTypeEnum.FORM_DATA,
      // @ts-ignore
      ignoreCancelToken: true,
    },
    data,
  });
}
export function updateProfile(params) {
  return defHttp.put<string[]>({ url: Api.UpdateProfile, params });
}
export function doLogout() {
  return defHttp.post({ url: Api.Logout });
}
/**
 * @description 获取验证码
 */
export function getCaptcha(params) {
  return defHttp.get({ url: Api.GetCaptcha, params });
}
